package com.ruoyi.agriculture.zs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.agriculture.zs.domain.ZsQuestionComment;
import com.ruoyi.agriculture.zs.service.IZsQuestionCommentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评论Controller
 * 
 * @author zs
 * @date 2025-07-27
 */
@RestController
@RequestMapping("/zs/QuestionComment")
public class ZsQuestionCommentController extends BaseController
{
    @Autowired
    private IZsQuestionCommentService zsQuestionCommentService;

    /**
     * 查询评论列表
     */
    @PreAuthorize("@ss.hasPermi('zs:QuestionComment:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZsQuestionComment zsQuestionComment)
    {
        startPage();
        List<ZsQuestionComment> list = zsQuestionCommentService.selectZsQuestionCommentList(zsQuestionComment);
        return getDataTable(list);
    }

    /**
     * 查询问题评论列表（前台使用，无需权限）
     */
    @GetMapping("/listByQuestionId/{zsQuestionId}")
    public TableDataInfo listByQuestionId(@PathVariable("zsQuestionId") Long zsQuestionId)
    {
        ZsQuestionComment zsQuestionComment = new ZsQuestionComment();
        zsQuestionComment.setZsQuestionId(zsQuestionId);
        startPage();
        List<ZsQuestionComment> list = zsQuestionCommentService.selectZsQuestionCommentList(zsQuestionComment);
        return getDataTable(list);
    }

    /**
     * 导出评论列表
     */
    @PreAuthorize("@ss.hasPermi('zs:QuestionComment:export')")
    @Log(title = "评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZsQuestionComment zsQuestionComment)
    {
        List<ZsQuestionComment> list = zsQuestionCommentService.selectZsQuestionCommentList(zsQuestionComment);
        ExcelUtil<ZsQuestionComment> util = new ExcelUtil<ZsQuestionComment>(ZsQuestionComment.class);
        util.exportExcel(response, list, "评论数据");
    }

    /**
     * 获取评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('zs:QuestionComment:query')")
    @GetMapping(value = "/{zsCommentId}")
    public AjaxResult getInfo(@PathVariable("zsCommentId") Long zsCommentId)
    {
        return success(zsQuestionCommentService.selectZsQuestionCommentByZsCommentId(zsCommentId));
    }

    /**
     * 新增评论
     */
    @PreAuthorize("@ss.hasPermi('zs:QuestionComment:add')")
    @Log(title = "评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZsQuestionComment zsQuestionComment)
    {
        return toAjax(zsQuestionCommentService.insertZsQuestionComment(zsQuestionComment));
    }

    /**
     * 前台新增评论（无需权限）
     */
    @Log(title = "评论", businessType = BusinessType.INSERT)
    @PostMapping("/addComment")
    public AjaxResult addComment(@RequestBody ZsQuestionComment zsQuestionComment)
    {
        return toAjax(zsQuestionCommentService.insertZsQuestionComment(zsQuestionComment));
    }

    /**
     * 修改评论
     */
    @PreAuthorize("@ss.hasPermi('zs:QuestionComment:edit')")
    @Log(title = "评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZsQuestionComment zsQuestionComment)
    {
        return toAjax(zsQuestionCommentService.updateZsQuestionComment(zsQuestionComment));
    }

    /**
     * 删除评论
     */
    @PreAuthorize("@ss.hasPermi('zs:QuestionComment:remove')")
    @Log(title = "评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{zsCommentIds}")
    public AjaxResult remove(@PathVariable Long[] zsCommentIds)
    {
        return toAjax(zsQuestionCommentService.deleteZsQuestionCommentByZsCommentIds(zsCommentIds));
    }
}
